import { EStorageKey, IConfig } from "../../utils";

/** 存储数据 */
export const setStorageData = async <T extends EStorageKey>(key: T, data: IConfig[T]): Promise<Boolean> => {
  try {
    await chrome.storage.local.set({
      [key]: data
    })
    return true
  }
  catch (error) {
    return false
  }
}

/** 存储数据 */
export const getStorageData = async <T extends EStorageKey>(key: T): Promise<IConfig[T] | undefined> => {
  try {
    const result = await chrome.storage.local.get(key)
    return result[key]
  }
  catch (error) {
    return undefined
  }
}